package com.sskj.qiangjin.ui.fragment;


import android.text.TextUtils;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Autowired;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.robinhood.ticker.TickerView;
import com.sskj.common.util.ClickUtil;
import com.sskj.common.util.NumberUtil;
import com.sskj.lib.RConfig;
import com.sskj.lib.base.BaseFragment;
import com.sskj.qiangjin.R;
import com.sskj.qiangjin.bean.BankersMainBean;
import com.sskj.qiangjin.presenter.BankerJackpotMainFragmentPresenter;
import com.sskj.qiangjin.ui.CircleView;

import butterknife.BindView;


@Route(path = RConfig.APP_FRAGMENT_BANKER_JACKPOT_MAIN)//主页
public class BankerJackpotMainFragment extends BaseFragment<BankerJackpotMainFragmentPresenter> {
    @BindView(R.id.tv_more_jackpot)
    TextView tvMoreJackpot;
    @BindView(R.id.tickerView)
    TickerView tickerView;
    @BindView(R.id.circle_view)
    CircleView circleView;
    @Autowired
    String moneyType;
    @BindView(R.id.tv_banker_fund)
    TextView tvBankerFund;
    @BindView(R.id.tv_pool_fund)
    TextView tvPoolFund;
    @BindView(R.id.tv_banker_profits)
    TextView tvBankerProfits;
    @BindView(R.id.tv_pool_profits)
    TextView tvPoolProfits;
    @BindView(R.id.ll_more_msg)
    LinearLayout llMoreMsg;

    @Override
    protected int getLayoutId() {
        return R.layout.app_fragment_banker_jackpot_main;
    }

    @Override
    public BankerJackpotMainFragmentPresenter getPresenter() {
        return new BankerJackpotMainFragmentPresenter();
    }

    @Override
    public void setUserVisibleHint(boolean isVisibleToUser) {
        super.setUserVisibleHint(isVisibleToUser);
        if (TextUtils.isEmpty(moneyType)) {
            return;
        }
        mPresenter.getBankerPoolMainMsg(moneyType.equals("QC") ? "pb" : moneyType.equals("USDT") ? "cny" : "usdt");
    }

    @Override
    public void onHiddenChanged(boolean hidden) {
        super.onHiddenChanged(hidden);
        if (!hidden) {
            mPresenter.getBankerPoolMainMsg("cny");
        }
    }

    @Override
    public void initView() {
        ARouter.getInstance().inject(this);
        mPresenter.getBankerPoolMainMsg(moneyType.equals("QC") ? "pb" : moneyType.equals("USDT") ? "cny" : "usdt");
        ClickUtil.click(llMoreMsg, () -> {
            ARouter.getInstance().build(RConfig.APP_FAQ).navigation();
        });
    }

    public void updataUi(BankersMainBean data) {
        tvBankerFund.setText(data.getBank_money() + " " + moneyType);
        tvPoolFund.setText(data.getBank_money_total() + " " + moneyType);
        tvBankerProfits.setText(data.getBank_money_lirun() + " " + moneyType);
        tvPoolProfits.setText(data.getBank_money_lirun_total() + " " + moneyType);
        tickerView.setText(NumberUtil.keep2(Float.valueOf(data.getScale()) * 100) + "%");
        circleView.setProgressNum(Float.valueOf(data.getScale()) * 100, 1000);
    }
}
